<!DOCTYPE HTML>
<html>
<head>
<title>StringLeft / StringRight | AutoHotkey</title>
<meta name="description" content="The StringLeft and StringRight commands retrieve a number of characters from the left or right-hand side of a string." />
<meta name="ahk:equiv-v2" content="lib/SubStr.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>StringLeft / StringRight</h1>

<p>从字符串的左边或右边提取一些字符.</p>

<p class="warning"><strong>过时的:</strong> 不推荐在新脚本中使用这些命令. 请使用 <a href="SubStr.htm">SubStr</a> 函数代替.</p>

<pre class="Syntax">
<span class="func">StringLeft</span>, OutputVar, InputVar, Count
<span class="func">StringRight</span>, OutputVar, InputVar, Count
</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>OutputVar</dt>
  <dd><p>用来存储从 <em>InputVar</em> 提取的子字符串的输出变量的名称.</p></dd>

  <dt>InputVar</dt>
  <dd><p>需要被提取的输入变量的名称. 不要把名称括在百分号中, 除非您希望使用变量的 <em>内容</em> 作为被解析的变量名.</p></dd>

  <dt>Count</dt>
  <dd><p>需提取的字符数, 可以为<a href="../Variables.htm#Expressions">表达式</a>. 如果 <em>Count</em> 小于或等于零, 那么 <em>OutputVar</em> 会被置空. 如果 <em>Count</em> 超过了 <em>InputVar</em> 的长度, 那么 <em>OutputVar</em> 会被置为 <em>InputVar</em> 的完整内容.</p></dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>在这个及其他所有命令中, <em>OutputVar</em> 和 <em>InputVar</em> 中可以使用相同的变量.</p>
<h2 id="Related">相关</h2>
<p><a href="SubStr.htm">SubStr()</a>, <a href="StringMid.htm">StringMid</a>, <a href="StringTrimLeft.htm">StringTrimLeft</a>, <a href="StringTrimLeft.htm">StringTrimRight</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringGetPos.htm">StringGetPos</a>, <a href="StringLen.htm">StringLen</a>, <a href="StringLower.htm">StringLower</a>, <a href="StringLower.htm">StringUpper</a>, <a href="StringReplace.htm">StringReplace</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExLeft">
<p><a class="ex_number" href="#ExLeft"></a> 保存字符串 "This" 到 <var>OutputVar</var>.</p>
<pre>String := "This is a test." 
StringLeft, OutputVar, String, 4</pre>
</div>

<div class="ex" id="ExRight">
<p><a class="ex_number" href="#ExRight"></a> 保存字符串 "test." 到 <var>OutputVar</var>.</p>
<pre>String := "This is a test."
StringRight, OutputVar, String, 5</pre>
</div>

</body>
</html>